package com.littlepay.kr4.paulin.dfeba77.remind;

/**
 * Created by john on 2017/6/8.
 */

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.littlepay.kr4.paulin.dfeba77.MainActivity;
import com.littlepay.kr4.paulin.dfeba77.R;

/**
 * Display the alarm information
 */
public class MyAlarm extends Activity {

    /**
     * An identifier for this notification unique within your application
     */
    public static final int NOTIFICATION_ID=1;

    @Override


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_alarm);

        // create the instance of NotificationManager
        final NotificationManager nm=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        // create the instance of Notification
        //Notification n=new Notification(R.drawable.gray_point,"this is a send",System.currentTimeMillis());
        Notification.Builder notification=new Notification.Builder(this).setContentTitle("是时候记下账了").setContentText("来自小账本的提醒");
        Intent broadcastIntent = new Intent(this, NotificationReceiver.class);
        PendingIntent pendingIntent = PendingIntent.
                getBroadcast(this, 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setContentIntent(pendingIntent);


        //Intent clikIntent = new Intent(this,)
        Notification n = notification.setSmallIcon(R.drawable.ic_launcher).setWhen(System.currentTimeMillis()).setTicker("飘过～～～").build();  //分别设置通知标题、通知内容、通知图标、通知时间和通知提示。
        nm.notify(1,n);

        //n.setLatestEventInfo(getApplicationContext(),"This is Notice title","This is Notice text",null);
        //n.setLatestEventInfo(context,"This is Notice title","This is Notice text",null);
        /* set the sound of the alarm. There are two way of setting the sound */
        // n.sound=Uri.parse("file:///sdcard/alarm.mp3");
        //n.sound=Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "20");
        //n.describeContents();
        // Post a notification to be shown in the status bar
        //nm.notify(NOTIFICATION_ID, n);




        /* display some information */
       TextView tv=(TextView)findViewById(R.id.tvNotification);
        tv.setText("欢迎回来！");

        /* the button by which you can cancel the alarm */
       Button btnCancel=(Button)findViewById(R.id.btnCancel);
        btnCancel.setOnClickListener(new View.OnClickListener() {

           @Override
           public void onClick(View arg0) {
               nm.cancel(NOTIFICATION_ID);
               Intent tomian  = new Intent(MyAlarm.this,MainActivity.class);
               startActivity(tomian);
               finish();
           }
        });
    }



}
